<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="cn.zqy.model.BookLanguage" %>
<%@ page import="cn.zqy.model.BookStatus" %>
<%@ page import="cn.zqy.model.Library" %>
<%@ page import="cn.zqy.model.LibraryActions" %>
<%@ page import="cn.zqy.services.LibraryService" %>
<%@ page import="cn.zqy.services.Utils" %>
<%
String bookNo=request.getParameter("book_no");
String flag=request.getParameter("flag");
HashMap<String,String> paramsMap=new HashMap<String,String>();
paramsMap.put("bookNo",bookNo);
ArrayList<Library> libraryList=new LibraryService().retrieveAll(paramsMap);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Library Update</title>
<link rel="stylesheet" type="text/css" href=""/>
<script type="text/javascript">
function doSubmit()
{
	document.getElementById("frm").submit();
	//window.close();
}
</script>
</head>
<body>
<input type="button" value="back" onclick="history.go(-1);">
<%
if(libraryList.size()>0)
{
	Library library=libraryList.get(0);
	String bookName=library.getBookName()==null?"":library.getBookName();
	String bookStatus=library.getBookStatus()==null?"":library.getBookStatus();
	String bookLanguage=library.getLanguage()==null?"":library.getLanguage();
	String borrower=library.getBorrower()==null?"":library.getBorrower();
	String bookOwner=library.getBookOwner()==null?"":library.getBookOwner();
	out.println("<form name='frm' id='frm' action='/Library' method='post'>");
	out.println("<input type='hidden' name='book_no' value='"+bookNo+"'/>");
	out.println("<input type='hidden' name='flag' value='"+flag+"'/>");
	out.println("<table align='center'>");
	if(LibraryActions.LEND.toString().equalsIgnoreCase(flag))
	{
		out.println("<tr><td>please input the borrower:</td><td><input type='text' name='borrower' /></td>");
	}
	else if(LibraryActions.RESERVE.toString().equalsIgnoreCase(flag))
	{
		out.println("<tr><td>please input your email:</td><td><input type='text' name='contact' /></td>");			
	}
	else if(LibraryActions.UPDATE.toString().equalsIgnoreCase(flag))
	{
		String bookStatusSelect=Utils.createHtmlSelect("book_status",BookStatus.IN.getAllDesc(),BookStatus.IN.getAllValue(),bookStatus);
		String bookLanguageSelect=Utils.createHtmlSelect("book_language",BookLanguage.ALL.getAllDesc(),BookLanguage.ALL.getAllValue(),bookLanguage);
		out.println("<tr><td>Name:</td><td><input type='text' name='book_name' value='"+bookName+"' /></td>");		
		out.println("<tr><td>Language:</td><td>"+bookLanguageSelect+"</td>");
		out.println("<tr><td>Status:</td><td>"+bookStatusSelect+"</td>");
		out.println("<tr><td>Borrower:</td><td><input type='text' name='borrower' value='"+borrower+"' /></td>");
		out.println("<tr><td>Owner:</td><td><input type='text' name='book_owner' value='"+bookOwner+"' /></td>");
	}
	else if(LibraryActions.DELETE.toString().equalsIgnoreCase(flag))
	{
		out.println("<tr><td>No:</td><td>"+bookNo+"</td>");
		out.println("<tr><td>Name:</td><td>"+bookName+"</td>");		
		out.println("<tr><td>Language:</td><td>"+bookLanguage+"</td>");
		out.println("<tr><td>Status:</td><td>"+bookStatus+"</td>");
		out.println("<tr><td>Borrower:</td><td>"+borrower+"</td>");
		out.println("<tr><td>Owner:</td><td>"+bookOwner+"</td>");
	}
	out.println("<tr><td colspan='2' align='center'><input type='button' value='"+flag+"' onclick='doSubmit();'/></td></tr>");
	out.println("<table>");
}
else
{
	out.println("<span align='center'><a href='/library.jsp'>Return</a></span>");
}
%>
</body>
</html>